package com.briup.jz.service.impl;

import com.briup.jz.bean.CertificationApply;
import com.briup.jz.bean.CertificationApplyExample;
import com.briup.jz.bean.extend.CertificationApplyExtend;
import com.briup.jz.dao.CertificationApplyMapper;
import com.briup.jz.dao.extend.CertificationApplyExtendMapper;
import com.briup.jz.service.ICertificationApplyService;
import com.briup.jz.utils.CustomerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;

@Service
public class CertificationApplyServiceImpl implements ICertificationApplyService {

    @Autowired
    private CertificationApplyMapper certificationApplyMapper;

    @Autowired
    private CertificationApplyExtendMapper certificationApplyExtendMapper;


    @Override
    public void saveOrUpdate(CertificationApply certificationApply) throws CustomerException {
        if (certificationApply.getId()==null){
            certificationApplyMapper.insert(certificationApply);
        }else {
            certificationApplyMapper.updateByPrimaryKey(certificationApply);
        }
    }

    @Override
    public void deleteById(long id) throws CustomerException {
        CertificationApply certificationApply = certificationApplyMapper.selectByPrimaryKey(id);
        if (certificationApply==null){
            throw new CustomerException("要删除的实名认证申请不存在");
        }
        certificationApplyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<CertificationApplyExtend> queryWithBaseUser(Long startTime, Long endTime, String status, Long userId) {
        return certificationApplyExtendMapper.select(startTime, endTime, status, userId);
    }

    @Override
    public List<CertificationApply> query(Long startTime, Long endTime, String status, Long userId) {
        CertificationApplyExample example = new CertificationApplyExample();
        CertificationApplyExample.Criteria criteria = example.createCriteria();
        if (startTime!=null && endTime!=null){
            criteria.andApplyTimeGreaterThan(startTime);
            criteria.andApplyTimeLessThanOrEqualTo(endTime);
        }
        if (status!=null){
            criteria.andStatusEqualTo(status);
        }
        if(userId!=null) {
            criteria.andUserIdEqualTo(userId);
        }
        return certificationApplyMapper.selectByExample(example);
    }
}
